import cv2
from PIL import Image

def rotate_image_180_flip(image_path, output_path):
    """
    使用翻转方式将图片旋转180度。

    :param image_path: 输入图片的路径
    :param output_path: 旋转后图片保存的路径
    """
    # 读取图片
    img = cv2.imread(image_path)
    if img is None:
        print(f"无法加载图像: {image_path}")
        return

    # 同时进行水平和垂直翻转，相当于旋转180度
    rotated_img = cv2.flip(img, -1)

    # 保存旋转后的图片
    cv2.imwrite(output_path, rotated_img)
    print(f"图片已成功旋转180度并保存为 '{output_path}'")



def rotate_image_90_flip(image_path, output_path):
    # 加载图片
    image = Image.open(image_path)

    # 旋转图片90度
    rotated_image = image.rotate(-90, expand=True)

    # 保存旋转后的图片
    rotated_image.save(output_path)

    print(f"图片已成功旋转90度并保存为 '{output_path}'")

# 示例用法
if __name__ == "__main__":
    input_image_path = 'output.png'  # 替换为你的输入图片路径
    output_image_path = 'output.png'  # 替换为你
    rotate_image_90_flip(input_image_path, output_image_path)